<style type="text/css">
.channellist{
	margin:20px;
}
.channeltree{
	width:80%;
}
.channeltree img,.channeltree span{
	cursor:pointer;
	float:left;
	margin-right:4px;
}
.channeltree .name{
}
.channeltree .edit,.channeltree .add,.channeltree .delete{
	cursor:pointer;
}
.channeltree .edit:hover,.channeltree .add:hover,.channeltree .delete:hover{
	text-decoration:underline;
}
.channeltree .edit{
	color:#00F;
}
.channeltree .add{
	color:#0F0;
}
.channeltree .delete{
	color:#F00;
}
.channeladd{
	display:none;
}
.channeladd label{
	display:block;
}
.channeladd .button{
	text-align:center;
}
.channeladd .button button{
	margin:10px 10px;
	text-align:center;
}
</style>
<script type="text/javascript">
$(document).ready(function(e) {
	dialog('.channeladd',{
		autoOpen:false,
		modal:true,
		resizable:false,
		title:'添加网站模块',
		width:400
	});
	$('.channeltree').jTree();
	$('.channeltree').jTree.showAll();
});
function channeledit(id){
	goPage('system/channel!detail.action?id='+id,'#main')
}
function showchanneladd(parentid){
	$('.channeladd input[name=parentid]').val(parentid);
	$('.channeladd .parent').text('父级模块：'+$('#'+parentid+' .name').text());
	$('.channeladd').dialog('open');
}
function channeladd(){
	if(checkForm($('.channeladd *[name]'))){
		$.ajax({
			url:'system/channel!addAction.action',
			type:'POST',
			data:serializeArray($('.channeladd *[name]')),
			dataType:"JSON",
			success: function(rs){
				if(rs.code=='0'){
					$('.channeladd').dialog('close');
					goPage('system/channel.action','#main')
				}else{
					alert(rs.msg);
				}
			}
		});
	}
}
function channeldel(_this,id){
	var child=$(_this).parent().next('.treechild');
	if(child.length>0){
		alert('对不起该模块包含子模块，不可删除！');
		return ;
	}
	if(!confirm('确定删除此模块吗？')){
		return;
	}
	$.getJSON('system/channel!delete.action',{id:id},function(rs){
		if(rs.code=='1'){
			goPage('system/channel.action','#main')
		}else{
			alert(rs.msg);
		}
	});
}
</script>
<div class="channellist">
  <h3>模板关系结构</h3>
  <div class="channeltree">
  	<div id="0">
      <span class="name"><img src="/images/tree_tip.png" >顶级模块</span>
      <span class="add" onClick="showchanneladd('0')">添加</span>
    </div>
    <#list channels as m>
    <div id="${m._id}" pid="${m.parentid}"><img src="/images/tree_tip.png" >
      <span class="name" onClick="channeledit('${m._id}')">${m.name}</span>
      <span class="edit" onClick="channeledit('${m._id}')">查看</span>
      <span class="add" onClick="showchanneladd('${m._id}')">添加</span>
      <span class="delete" onClick="channeldel(this,'${m._id}')">删除</span>
    </div>
    </#list>
  </div>
  <div class="channeladd">
    <input type="hidden" name="parentid" regx="${check.parentid}" />
    <label class="parent"></label>
    <label>模块名称：<input type="text" name="name" regx="${check.name}" /></label>
    <label>排　　序：<input type="text" name="index" regx="${check.index}" /></label>
    <label>关 键 词：<input type="text" name="key" regx="${check.key}" /></label>
    <label>模块类型：<select name="type">
    	<option value="article">内容显示</option>
    	<option value="list">内容列表</option>
    	<option value="url">超链接</option>
        </select></label>
    <label>访问地址：<input type="text" name="url" regx="${check.url}" /></label>
    <div class="button">
      <button type="button" onClick="channeladd()">提交</button>
      <button type="button" onClick="$('.channeladd').dialog('close');">取消</button>
    </div>
  </div>
</div>